﻿@model IEnumerable<MasPurchaseMethod>

@{
    ViewBag.Title = "วิธีการจัดหา";
    //ViewBag.Descr = "เก็บข้อมูลหน่วยนับของพัสดุหรือวัสดุต่างๆในระบบ";
}

@using (Html.BeginForm("Index", "MasPurchaseMethod", FormMethod.Post, new { @id = "form" }))
{
    @Html.AntiForgeryToken()
    <div class="row-fluid">
        <div class="block-button-menu-above">
            @Html.ButtonAdd()
            @Html.ButtonDeleteAll()
        </div>
        @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })
        <div class="row-fluid">
            <div class="table-header span12">
				<div class="span10">@ViewBag.Title</div>
				@Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width:50px;">
						<!-- Check box delete multiple records column-->
                        <label>
                            <input type="checkbox" />
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th>
                       @Html.DisplayName("รายการวิธีจัดหา")
                    </th>
                    <th>
                        @Html.DisplayName("ประเภทการจัดหา")
                    </th>
                    <th>
                        @Html.DisplayName("รายละเอัยด")
                    </th>
                    <th>
                        @Html.DisplayName("เหตุผล")
                    </th>
                    <th>
                        @Html.DisplayName("ประกาศ")
                    </th>
                    <th>
                        @Html.DisplayName("วงเงินต่ำสุด")
                    </th>
                    <th>
                        @Html.DisplayName("วงเงินสูงสุด")
                    </th>
					<th class="center" style="width:80px;">
						<!-- Empty head column for export buttons -->&nbsp;
					</th>
                </tr>
            </thead>

            <tbody>
                @foreach(var m in Model)
                {
                    <tr>
                        <td class="center">
							<!-- Check box all for delete multiple records -->
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.PcMethodId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>
						<td>
                            @Html.ActionLink(@m.Name, "Details", new { Id=m.PcMethodId })
						</td>
						<td>
                            @Html.DisplayFor(modelItem => m.MasPurchaseType.PcTypeName)
						</td>
						<td>
							@Html.DisplayFor(modelItem => m.Descr)
						</td>
                        <td>
							@Html.DisplayFor(modelItem => m.Reason)
						</td>
                        <td>
							@{if (m.IsBid == true)
                                {
                                    @Html.DisplayName("ใช้ประกาศ")
                                }else{
                                    @Html.DisplayName("ไม่ใช้ประกาศ")
                                }
           
                             }
						</td>
                        <td>
							@Html.DisplayFor(modelItem => m.AmountMin)
						</td>
                        <td>
							@Html.DisplayFor(modelItem => m.AmountMax)
						</td>
                        <td class="td-actions">
							@Html.Partial("_ButtonMenuEachRow", new ExportGrid
								{
									Id=m.PcMethodId, 
									DetailsUrl = Url.Action("Details") + "/" + m.PcMethodId,
									EditUrl = Url.Action("Edit") + "/" + m.PcMethodId,
									DeleteUrl = Url.Action("Delete") + "/" + m.PcMethodId
									
								})
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@section scripts {
<script type="text/javascript">
    $('#table').dataTable({
        "aoColumns": [
            { "bSortable": false },
            null,
            null,
            null,
            null,
            null,
            null,
            null
            ,{ "bSortable": false }
        ]
    });
	$(function () {
		

		$('table th input:checkbox').on('click', function () {
		    var that = this;
		    $(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function () {
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});

		});

		$('[data-rel=tooltip]').tooltip();

		$("#form").submit(function (e) {
		    e.preventDefault();
		    var currentForm = this;
			bootbox.confirm("คุณแน่ใจหรือไม่", function(c) {
			    if (c) {
			    	$.ajax({
					    url: "@Url.Action("DeleteAll")",
						type: "post",
						dataType: "json",
						data: $(currentForm).serialize(),
						context: document.body,
					    success: function(s) { 
					    	if (s.success) {
					    		location.reload();
					    	}
					    },
					    error: function (xhr, status, error) {
					    	alert("Status: " + status + ", Error: " + error + ", XHR: " + xhr.readyState);
					    },
					    statusCode: {
					    	404: function () {
					    		alert("Page not found");
					    	}
					    }
					}); 
				}
			});
		    return false;
		}); 
	})

</script>
}